#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
struct Node {
  int val, sum, tag;
  int fa, ch[2];
} tr[N];
#define val(p) tr[p].val
#define sum(p) tr[p].sum
#define tag(p) tr[p].tag
#define fa(p) tr[p].fa
#define lc(p) tr[p].ch[0]
#define rc(p) tr[p].ch[1]
#define notroot(p) (lc(fa(p)) == p) || (rc(fa(p)) == p)
void pushup(int p) { sum(p) = sum(lc(p)) ^ sum(rc(p)) ^ val(p); }
void pushdown(int p) {
  if (tag(p)) {
    swap(lc(p), rc(p));
    tag(lc(p)) ^= 1;
    tag(rc(p)) ^= 1;
    tag(p) = 0;
  }
}
void pushall(int x) {
  if (notroot(x)) pushall(fa(x));
  pushdown(x);
}
void rotate(int x) {
  int y = fa(x), z = fa(y);
  int k = rc(y) == x;
  if (notroot(y)) tr[z].ch[rc(z) == y] = x;
  fa(x) = z;
  tr[y].ch[k] = tr[x].ch[k ^ 1];
  fa(tr[x].ch[k ^ 1]) = y;
  tr[x].ch[k ^ 1] = y;
  fa(y) = x;
  pushup(y), pushup(x);
}
void splay(int x) {
  pushall(x);
  while (notroot(x)) {
    int y = fa(x), z = fa(y);
    if (notroot(y)) {
      if ((rc(y) == x) ^ (rc(z) == y))
        rotate(x);
      else
        rotate(y);
    }
    rotate(x);
  }
}
void access(int x) {  // link from x to root
  for (int y = 0; x;) {
    splay(x);
    rc(x) = y;
    pushup(x);
    y = x;
    x = fa(x);
  }
}
void makeroot(int x) {
  access(x);
  splay(x);
  tag(x) ^= 1;
}
void split(int x, int y) {
  makeroot(x);
  access(y);
  splay(y);
}
void output(int x, int y) {
  split(x, y);
  cout << tr[y].sum << endl;
}
int findroot(int x) {
  access(x);
  splay(x);
  while (lc(x)) x = lc(x), pushdown(x);
  splay(x);
  return x;
}
void link(int x, int y) {
  makeroot(x);
  if (findroot(y) != x) fa(x) = y;
}
void cut(int x, int y) {
  makeroot(x);
  if (findroot(y) == x && fa(y) == x && !lc(y)) fa(y) = 0, pushup(x);
}
void change(int x, int y) {
  splay(x);
  val(x) = y;
  pushup(x);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) {
    cin >> val(i);
    sum(i) = val(i);
  }
  while (m--) {
    int op, x, y;
    cin >> op >> x >> y;
    if (op == 0)
      output(x, y);
    else if (op == 1)
      link(x, y);
    else if (op == 2)
      cut(x, y);
    else
      change(x, y);
  }
  return 0;
}